<template>
  <swiper :options="swiperOption">
    <swiper-slide v-for="(page, index) of pages" :key="index">
      <div class="index__items">
        <div class="item" v-for="item of page" :key="item.id">
          <div class="item__img"><img :src='item.imgUrl' alt=''></div>
          <p class="item__txt">{{item.desc}}</p>
        </div>
      </div>
    </swiper-slide>
  </swiper>
</template>

<script>
export default {
  name: 'indexItems',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import "~@/assets/css/varible.styl"
.index__items
  overflow: hidden;
  height: 0;
  width: 100%;
  margin-top: 10px;
  padding-bottom: 50%;
.item
  position: relative;
  float: left;
  width: 25%;
  height: 0;
  padding-bottom: 25%;
  background: #fff;
  .item__img
    box-sizing: border-box
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 44px;
    padding: 10px;
    img {
      height: 100%;
      width: 100%;
    }
  .item__txt
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 44px;
    line-height: 44px;
    text-align: center;
    txt-elipsis()
</style>
